package managedbean.SCM.DeliveryOrder; 
 
import entity.CRM.LineItem;
import entity.CRM.SaleOrder;
import javax.faces.event.ActionEvent;
import java.io.IOException;
import java.util.List; 
import javax.ejb.EJB; 
import javax.ejb.EJBException;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.ViewScoped; 
import javax.faces.context.FacesContext;
import session.stateless.CRM.SaleOrderBeanLocal;
import session.stateless.FRM.CreditAccountBeanLocal;
 
@ManagedBean(name="viewConfirmedSaleOrderManagerBean")
@ViewScoped 
public class ViewConfirmedSaleOrderManagerBean { 
    @EJB 
    private SaleOrderBeanLocal saleOrderBeanLocal; 
    @EJB
    private CreditAccountBeanLocal creditAccountBeanLocal;
    
    private SaleOrder selectedSaleOrder;
    private List<LineItem> lineItems;
    private String statusMessage;
    
    public ViewConfirmedSaleOrderManagerBean() { 
    } 
 
 
    public List<SaleOrder> getConfirmedSaleOrders() throws EJBException
    { 
        //System.out.println("ViewSaleOrderManagerBean getSaleOrders method test b4 return");
        List<SaleOrder> temp = saleOrderBeanLocal.getSaleOrders_Confirmed();
        //System.out.println("ViewSaleOrderManagerBean getSaleOrders method after get list" +temp.size());
        return temp;
    } 
    
    public SaleOrder getSelectedSaleOrder() {
        return selectedSaleOrder;
    }

    public void setSelectedSaleOrder(SaleOrder selectedSaleOrder) {
        this.selectedSaleOrder = selectedSaleOrder;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }

    public SaleOrderBeanLocal getSaleOrderBeanLocal() {
        return saleOrderBeanLocal;
    }

    public void setSaleOrderBeanLocal(SaleOrderBeanLocal saleOrderBeanLocal) {
        this.saleOrderBeanLocal = saleOrderBeanLocal;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public void createDeliveryOrder(ActionEvent event) throws IOException
    {
        SaleOrder selectedSaleOrder = this.getSelectedSaleOrder();
        try
        {
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedSaleOrder", selectedSaleOrder);
            FacesContext.getCurrentInstance().getExternalContext().redirect("../deliveryOrder/addDeliveryOrder.xhtml");
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    }
} 